home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 50
/
Volume 50 - JOGO DISK .iso
/
Games
/
moonstonemadness.swf
/
scripts
/
__Packages
/
Library
/
Sound
/
SoundItem.as
next >
Wrap
Text File
|
2007-09-27
|
5KB
|
194 lines
class Library.Sound.SoundItem
{
static var FADE_RATE = 8;
static var FADE_AT_END_TIME = 800;
function SoundItem(__sndObject, __sLinkage, __nVolume, __nLoop, __sCategory, __mc)
{
this.sndObj = __sndObject;
this.sLinkage = __sLinkage;
this.mcRef = __mc;
this.nRemainingLoop = __nLoop;
this.nCurrentVolume = __nVolume;
this.nTargetVolume = __nVolume;
this.nFadeRate = Library.Sound.SoundItem.FADE_RATE;
this.sCategory = __sCategory;
this.bFadeAtEnd = false;
this.bMuted = false;
this.bPaused = false;
this.bNeedFreshStart = false;
this.sndObj.onSoundComplete = Library.Utils.Delegate.create(this,this.doSoundComplete);
this.sndObj.start(0,__nLoop);
this.sndObj.setVolume(this.returnComputedVolume(this.nCurrentVolume));
this.nCurrentTime = 0;
this.aEventListeners = new Array();
}
function doEnterFrame()
{
if(!this.bPaused)
{
if(this.nCurrentTime > this.sndObj.position)
{
this.nRemainingLoop = this.nRemainingLoop - 1;
}
this.nCurrentTime = this.sndObj.position;
}
this.doCheckFadeAtEnd();
this.doManageFade();
}
function doAddListener(__oListener)
{
this.aEventListeners.push(__oListener);
}
function doRemoveListener(__oListener)
{
var _loc2_ = 0;
while(_loc2_ < this.aEventListeners.length)
{
if(this.aEventListeners[_loc2_] == __oListener)
{
delete this.aEventListeners[_loc2_];
this.aEventListeners.splice(_loc2_,1);
}
_loc2_ = _loc2_ + 1;
}
}
function doSoundComplete()
{
if(this.bNeedFreshStart && this.nRemainingLoop > 1)
{
this.sndObj.start(0,this.nRemainingLoop - 1);
}
else
{
this.doManageEndEvent();
}
}
function doUpdateSound()
{
this.sndObj.setVolume(this.returnComputedVolume(this.nCurrentVolume));
}
function doMute()
{
this.bMuted = true;
this.doUpdateSound();
}
function doUnMute()
{
this.bMuted = false;
this.doUpdateSound();
}
function doPause()
{
this.sndObj.stop();
this.bPaused = true;
}
function doResume()
{
this.bPaused = false;
this.bNeedFreshStart = true;
this.sndObj.start(this.nCurrentTime / 1000,1);
}
function doStop()
{
this.sndObj.stop();
this.doManageEndEvent();
}
function doFadeTo(__nVolume, __bStopAndDelete)
{
if(__bStopAndDelete == undefined)
{
__bStopAndDelete = true;
}
this.bStopAfterFade = __bStopAndDelete;
this.nTargetVolume = __nVolume;
}
function setFadeRate(__nRate)
{
if(__nRate == undefined)
{
__nRate = Library.Sound.SoundItem.FADE_RATE;
}
this.nFadeRate = __nRate;
}
function setFadeAtEnd(__bFadeAtEnd)
{
this.bFadeAtEnd = true;
}
function setPan(__nPan)
{
this.sndObj.setPan(__nPan);
}
function get Category()
{
return this.sCategory;
}
function get LinkageName()
{
return this.sLinkage;
}
function doDestroy()
{
this.sndObj.stop();
delete this.sndObj;
this.mcRef.removeMovieClip();
}
function doCheckFadeAtEnd()
{
if(this.bFadeAtEnd)
{
if(this.nRemainingLoop == 1)
{
if(this.sndObj.duration - this.nCurrentTime <= Library.Sound.SoundItem.FADE_AT_END_TIME)
{
this.doFadeTo(0);
}
}
}
}
function doManageEndEvent()
{
var _loc2_ = 0;
while(_loc2_ < this.aEventListeners.length)
{
this.aEventListeners[_loc2_].doSoundEvent(Library.Sound.SoundManager.EVENT_SOUND_COMPLETE,this);
_loc2_ = _loc2_ + 1;
}
this.aEventListeners = new Array();
this.mcRef.removeMovieClip();
delete this.mcRef;
delete this.aEventListeners;
delete this.sndObj.onSoundComplete;
delete this.sndObj;
}
function doManageFade()
{
if(this.nCurrentVolume != this.nTargetVolume)
{
this.nCurrentVolume = Library.Utils.MoreMath.getReachNum(this.nCurrentVolume,this.nTargetVolume,this.nFadeRate);
this.sndObj.setVolume(this.returnComputedVolume(this.nCurrentVolume));
}
if(this.nCurrentVolume <= 0 && this.bStopAfterFade)
{
this.sndObj.stop();
this.doManageEndEvent();
}
}
function returnComputedVolume(__nVolume)
{
var _loc2_ = undefined;
if(!this.bMuted && !Library.Sound.SoundManager.isCategoryMuted(this.sCategory))
{
var _loc3_ = Library.Sound.SoundManager.__get__MasterVolume() / 100;
var _loc4_ = Library.Sound.SoundManager.getCategoryVolume(this.sCategory) / 100;
_loc2_ = __nVolume;
_loc2_ *= _loc4_;
_loc2_ *= _loc3_;
}
else
{
_loc2_ = 0;
}
return _loc2_;
}
}